﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Core;

namespace Yuanlin.Business
{
    public class ZiCaiCategories : YuanlinUserControl,
        IReplyConverter<ZiCaiInfoReply, GetListOperation>
    {
        protected Repeater list;
        private EntityList ziCais;
        public int kind = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.Kind);
        public string tradeType = UrlManager.Instance.GetParameterValue<string>(YuanlinParameterName.TradeType);

        public override void GetRequests(List<BaseRequestBinder> requestBinders)
        {
            if (!Page.IsPostBack)
            {
                //把类别下没有数据的去掉（不列出来）,只显示第2层资材类别
                requestBinders.Add(RequestHelper.BuildGetZiCaiListByZiCaiInfoRequest(this, UserIdFromGreenNum, tradeType, kind));
            }
        }

        private void BindData()
        {
            this.list.DataSource = ziCais;
            this.list.DataBind();
        }

        #region IReplyConverter<ZiCaiInfoReply,GetListOperation> Members

        public void ConvertReply(ZiCaiInfoReply reply, GetListOperation operation)
        {
            if (reply != null)
            {
                ziCais = reply.EntityList;
                if (!Page.IsPostBack)
                {
                    BindData();
                }
            }
        }

        #endregion
    }
}
